<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" >
     <!--插槽:table标题-->
      <template #tableTitle>
      </template>
     <!--操作栏-->
     <template #action="{ record }" >
        <TableAction :actions="getTableAction(record)" />
     </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{text}">
         <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->
      <template #pcaSlot="{text}">
         {{ getAreaTextByCode(text) }}
      </template>
      <template #fileSlot="{text}">
         <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
         <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
      </template>
     <template #img="{ text }">
       <TableImg :size="60" :simpleShow="true" :imgList="text" />
     </template>
    </BasicTable>
    <!-- 表单区域 -->
    <TOperationRecordsModal @register="registerModal" @success="handleSuccess"></TOperationRecordsModal>
  </div>
</template>

<script lang="ts" name="TOperationRecords-tOperationRecords" setup>
  import {ref, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction,TableImg} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import TOperationRecordsModal from './components/TOperationRecordsModal.vue'
  import {columns, searchFormSchema} from './InputUse.data';
  import {list, repush} from './InputUse.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  const checkedKeys = ref<Array<string | number>>([]);
  //注册model
  const [registerModal, {openModal}] = useModal();
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '消费记录',
           api: list,
           columns,
           canResize:false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: false,
      }
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext
  
  /**
     * 重推数据上链
     */
   async function handleRepush(record) {
      await repush({id: record.useId}, handleSuccess);
    }
   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }
  /**
   * 操作栏
   */
  function getTableAction(record){
    return [
      {
        label: '重推上链',
        popConfirm: {
          title: '确认重新推送?',
          confirm: handleRepush.bind(null, record),
        }
      }
    ]
  }



</script>

<style scoped>

</style>
